/*
 * iSnakeIntroductionPanel.java
 *
 * Created on January 4, 2007, 8:12 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package net.sf.iSnake.UI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import net.sf.iSnake.configuration.iSnakeConfiguration;

/**
 *
 * @author thelinuxmaniac
 */
public class iSnakeIntroductionPanel extends JPanel{

    private static iSnakeConfiguration conf;
    private String iSnakeTitle;
    private JButton nextButton;
    
    public static String iString = "iSnake - The Intelligent & Multiplayer Snake Game";
    private static String panelName = "iSnakeIntroductionPanel";
    
    public static Color iSnakeIntroductionPanelBackgroundColor = Color.BLACK;
    public static Color iSnakeIntroductionPaneliStringColor = new Color(81,81,81);
    
    public static Dimension iSnakeIntroductionPanelSize = new Dimension(800,500);
    
    
    public static Integer iString_Width;
    public static Integer iString_Height;
    
    /** Creates a new instance of iSnakeIntroductionPanel */
    public iSnakeIntroductionPanel(iSnakeConfiguration conf)    {
        this.conf = conf;
        setLayout(new GridBagLayout());
        setSize(iSnakeIntroductionPanelSize);
        setBackground(iSnakeIntroductionPanelBackgroundColor);
        
        nextButton = new JButton("");
        nextButton.setIcon(new ImageIcon(conf.getImageNext()));
        nextButton.setMnemonic('N');
        nextButton.setToolTipText("Click Here to Proceed");
        nextButton.setBorder(null);
        nextButton.setBorderPainted(false);
        nextButton.setContentAreaFilled(false);
        nextButton.setName("nextButtoniSnakeIntroPanel");
        nextButton.setRolloverEnabled(false);
        nextButton.setActionCommand("from_iSnakeIntroductionPanel_to_MainMenuPanel");
        
        add(nextButton,new GBC(0,0,1,1).setAnchor(GBC.SOUTHEAST).setWeight(1,1).setInsets(10));
    }
    
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        if(conf.getISnakeLogo() != null)   {
            g.drawImage(conf.getISnakeLogo(),getISnakeLogoX(),getISnakeLogoY(),null);
        }
        
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(iSnakeIntroductionPaneliStringColor);
                
        Font f = new Font(conf.iStringFont,Font.PLAIN,conf.iStringFontSize);
        g2.setFont(f);

        // measure the size of string to place the string just below the logo
        FontRenderContext context = g2.getFontRenderContext();
        Rectangle2D bounds = f.getStringBounds(iString,context);
        g2.drawString(iString,(int) (getWidth()-bounds.getWidth())/2,(int) (getISnakeLogoY()+bounds.getHeight()+220));
    }
   
    public int getISnakeLogoX()
    {
        return (getWidth() -conf.getISnakeLogo().getWidth(null))/2;
    }
    public int getISnakeLogoY()
    {
        return (getHeight() - conf.getISnakeLogo().getHeight(null))/2 -40;
    }

    public JButton getNextButton() {
        return nextButton;
    }

    public void setNextButton(JButton nextButton) {
        this.nextButton = nextButton;
    }

    public static String getPanelName() {
        return panelName;
    }

    public static void setPanelName(String aPanelName) {
        panelName = aPanelName;
    }
}